package com.me.mygdxgame.renderer.RenderObjects;

import android.annotation.TargetApi;
import android.os.Build;

import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class BaseObject
{
	public Vector3 vecWorld = new Vector3();
	public Vector3 vecEyeSpace = new Vector3();
	public Vector3 vecModelSpace = new Vector3();
	protected Matrix4 mModelMatrix = new Matrix4();
	protected Mesh mesh = null;
	protected Texture texture = null;
	
	public BaseObject()
	{
		MakeIdentity();
		getWorldPos();
	}
	
	public BaseObject(Mesh mesh)
	{
		MakeIdentity();
		getWorldPos();
		setMesh(mesh);
	}
	
	public void setTexture(Texture texture)
	{
		this.texture = texture;
	}
	
	public Texture getTexture()
	{
		return texture;
	}
	
	public Mesh getMesh()
	{
		return mesh;
	}
	
	public void setMesh(Mesh mesh)
	{
		this.mesh = mesh;
	}

	public Vector3 getWorldPos()
	{
		vecWorld.mul(mModelMatrix);
		
		return vecWorld;
	}
	
	
	
	public Vector3 getEyePos(PerspectiveCamera camera)
	{
		getWorldPos();
		
		vecEyeSpace.mul(camera.view);
		
		return vecEyeSpace;
	}

	public Matrix4 getModelMatrix()
	{
		return mModelMatrix;
	}

	public void rotate(float angle, float x, float y, float z)
	{
		mModelMatrix.rotate(x, y, z, angle);
	}

	public void MakeIdentity()
	{
		mModelMatrix.idt();
	}

	public void translate(float x, float y, float z)
	{
		mModelMatrix.translate(x, y, z);
	}
}
